package config;

/**
 * Created by ykj on 16/1/1.
 */

import com.jfinal.config.*;
import com.jfinal.ext.handler.UrlSkipHandler;
import com.jfinal.kit.Prop;
import com.jfinal.kit.PropKit;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.c3p0.C3p0Plugin;
import com.jfinal.render.ViewType;
import controller.*;
import model._MappingKit;

public class ApplicationConfig extends JFinalConfig {
    public void configConstant(Constants me) {
        me.setDevMode(true);
        me.setViewType(ViewType.JSP);
        me.setEncoding("utf-8");
    }

    public void configRoute(Routes me) {
        me.add("/index", IndexController.class);
        me.add("/admin", AdminController.class);
        me.add("/user", UserController.class);
        me.add("/type", TypeController.class);
        me.add("/product", ProductController.class);
        me.add("/purchases", PurchasesController.class);
    }

    public void configPlugin(Plugins me) {
        Prop p = PropKit.use("a_little_config.txt");
        C3p0Plugin c3p0Plugin = new C3p0Plugin(p.get("jdbcUrl"), p.get("user"), p.get("password"));
        me.add(c3p0Plugin);
        ActiveRecordPlugin arp = new ActiveRecordPlugin(c3p0Plugin);
        me.add(arp);
        _MappingKit.mapping(arp);
    }

    public void configInterceptor(Interceptors me) {
    }

    public void configHandler(Handlers me) {
        me.add(new MyUrlSkipHandler(".*jsp", false));
    }
}
